unit ufrmSales;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
  ActnList, ExtCtrls, DBGrids, StdCtrls, Buttons, DbCtrls;

type

  { TfrmSales }

  TfrmSales = class(TForm)
    actClose: TAction;
    actCancel: TAction;
    actDelete: TAction;
    actAdd: TAction;
    Action1: TAction;
    Action10: TAction;
    actEnter: TAction;
    actDot: TAction;
    actBack: TAction;
    actFind: TAction;
    actEditPrice: TAction;
    actEditQty: TAction;
    actEditPerc: TAction;
    actSl: TAction;
    actMult: TAction;
    actMinus: TAction;
    actPlus: TAction;
    Action2: TAction;
    Action3: TAction;
    Action4: TAction;
    Action5: TAction;
    Action6: TAction;
    Action7: TAction;
    Action8: TAction;
    Action9: TAction;
    actSave: TAction;
    ActionList: TActionList;
    DBGrid1: TDBGrid;
    dbgRest: TDBGrid;
    dbgSaleGroup: TDBGrid;
    edtBarCode: TEdit;
    Label1: TLabel;
    PageControl1: TPageControl;
    pnlBottom: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    pnlWork: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton21: TSpeedButton;
    SpeedButton22: TSpeedButton;
    SpeedButton23: TSpeedButton;
    SpeedButton24: TSpeedButton;
    SpeedButton25: TSpeedButton;
    SpeedButton26: TSpeedButton;
    SpeedButton27: TSpeedButton;
    SpeedButton28: TSpeedButton;
    SpeedButton29: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton30: TSpeedButton;
    SpeedButton31: TSpeedButton;
    SpeedButton32: TSpeedButton;
    SpeedButton33: TSpeedButton;
    SpeedButton34: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    Splitter1: TSplitter;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    UpDown1: TUpDown;
    UpDownRest: TUpDown;
    procedure actBackExecute(Sender: TObject);
    procedure actCloseExecute(Sender: TObject);
    procedure actDotExecute(Sender: TObject);
    procedure actEnterExecute(Sender: TObject);
    procedure actFindExecute(Sender: TObject);
    procedure Action10Execute(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Action2Execute(Sender: TObject);
    procedure Action3Execute(Sender: TObject);
    procedure Action4Execute(Sender: TObject);
    procedure Action5Execute(Sender: TObject);
    procedure Action6Execute(Sender: TObject);
    procedure Action7Execute(Sender: TObject);
    procedure Action8Execute(Sender: TObject);
    procedure Action9Execute(Sender: TObject);
    procedure dbgSaleGroupCellClick(Column: TColumn);
    procedure dbgSaleGroupColEnter(Sender: TObject);
    procedure dbgSaleGroupEnter(Sender: TObject);
    procedure dbgSaleGroupKeyPress(Sender: TObject; var Key: char);
    procedure dbgSaleGroupKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure dbgSaleGroupMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure dbgSaleGroupMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure pnlBottomClick(Sender: TObject);
    procedure SpeedButton24Click(Sender: TObject);
    procedure SpeedButton25Click(Sender: TObject);
    procedure SpeedButton26Click(Sender: TObject);
    procedure SpeedButton29Click(Sender: TObject);
    procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
  private
    { private declarations }
  public
    { public declarations }
    var Department_id : integer;
  end; 

var
  frmSales: TfrmSales;

implementation
uses uDataModule;

{$R *.lfm}

{ TfrmSales }

procedure TfrmSales.pnlBottomClick(Sender: TObject);
begin

end;

procedure TfrmSales.SpeedButton24Click(Sender: TObject);
begin
   edtBarCode.Text := edtBarCode.Text+'2';
end;

procedure TfrmSales.SpeedButton25Click(Sender: TObject);
begin

end;

procedure TfrmSales.SpeedButton26Click(Sender: TObject);
begin

end;

procedure TfrmSales.SpeedButton29Click(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'1';
  edtBarCode.SelStart:=100;
end;

procedure TfrmSales.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
   if Button = btPrev then DM.spSaleGroup.Next else DM.spSaleGroup.Prior;
end;

procedure TfrmSales.actCloseExecute(Sender: TObject);
begin
  Close;
end;

procedure TfrmSales.actBackExecute(Sender: TObject);
begin
    edtBarCode.text:= copy(edtBarCode.Text,1,Length(edtBarCode.Text)-1);
end;

procedure TfrmSales.actDotExecute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+DecimalSeparator;
end;

procedure TfrmSales.actEnterExecute(Sender: TObject);
begin
  actFind.Execute;
end;

procedure TfrmSales.actFindExecute(Sender: TObject);
begin
  with DM do
  begin
    spRestForSale.Close;
    spRestForSale.ParamByName('DEPARTMENT_ID').Value:= Department_id;
    spRestForSale.ParamByName('BARCODE').Value:= edtBarCode.Text;
    spRestForSale.Open;
    //SQLTransaction1.CommitRetaining;


  end;
end;

procedure TfrmSales.Action10Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'0';
end;

procedure TfrmSales.Action1Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'1';
end;

procedure TfrmSales.Action2Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'2';
end;

procedure TfrmSales.Action3Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'3';
end;

procedure TfrmSales.Action4Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'4';
end;

procedure TfrmSales.Action5Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'5';
end;

procedure TfrmSales.Action6Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'6';
end;

procedure TfrmSales.Action7Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'7';
end;

procedure TfrmSales.Action8Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'8';
end;

procedure TfrmSales.Action9Execute(Sender: TObject);
begin
  edtBarCode.Text := edtBarCode.Text+'9';
end;

procedure TfrmSales.dbgSaleGroupCellClick(Column: TColumn);
begin

end;

procedure TfrmSales.dbgSaleGroupColEnter(Sender: TObject);
begin

end;

procedure TfrmSales.dbgSaleGroupEnter(Sender: TObject);
begin

end;

procedure TfrmSales.dbgSaleGroupKeyPress(Sender: TObject; var Key: char);
begin
   //   edtBarCode.Text := DM.spSaleGroupSaleGroup.AsString;
  //edtBarCode.SelStart:=100;
end;

procedure TfrmSales.dbgSaleGroupKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

end;

procedure TfrmSales.dbgSaleGroupMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

end;

procedure TfrmSales.dbgSaleGroupMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    edtBarCode.Text := DM.spSaleGroupSaleGroup.AsString;
  edtBarCode.SelStart:=100;
end;

procedure TfrmSales.FormCreate(Sender: TObject);
begin
    DM.spSaleGroup.Open;
    DEPARTMENT_ID:=28;
end;

procedure TfrmSales.FormResize(Sender: TObject);
begin
  dbgRest.Width:=pnlBottom.Width-pnlWork.Width-UpDownRest.Width-5;
end;

procedure TfrmSales.FormShow(Sender: TObject);
begin
      edtBarCode.SetFocus;
      frmSales.WindowState:= wsMaximized;
end;

procedure TfrmSales.PageControl1Change(Sender: TObject);
begin

end;

end.

